package com.example.sulei.rootchangerinfo.hook;


import android.telephony.TelephonyManager;
import android.util.Log;

import com.example.sulei.rootchangerinfo.utils.Contans;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * 修改IMEI模块
 * Created by Sulei on 2017/4/14.
 */

public class IMEIHook extends BaseHook {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
        //获得Sharedpreference保存的数据,第一个参数为根包路径，不能填写this.getClass().getPackage().getName()
        //prefs.xml存储在data\data\com.example.sulei.rootchangerinfo\shared_prefs下，所以需要注意该参数！！！
        XSharedPreferences pre = new XSharedPreferences(Contans.PACKAGE_NAME, "prefs");
        hookMethod(TelephonyManager.class, "getDeviceId", pre.getString("imei", null));
//        hookMethod(com.android.internal.telephony.PhoneSubInfo, "getDeviceId", pre.getString("imei", null));

        Log.d("pre", "handleLoadPackage() returned imei: " + pre.getString("imei", null));
    }

}
